package com.demo.rabbitmq.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * 消费者手动ack
 */
@Slf4j
@Service
public class DeadLetterConsumer {

    @RabbitListener(id = "business_queue", queues = "dead_business_queue")
    public void directExchange3(Message message, Channel channel) throws Exception {
        try {
            throw new Exception("消费消息内容：" + new String(message.getBody()));
        } catch (Exception e) {
            log.error(e.getMessage());
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
        }
    }
}
